package parsing;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.List;

import scanning.Scanner;
import ast.Form;
import ast.Variable;

public class ParserTestBase {

	private List<Form> forms;

	protected void parse(String code) {
		Parser parser = new Parser(new Scanner(code));
		forms = new ArrayList<>();
		while (parser.hasNextForm())
			forms.add(parser.parseNextForm());
	}

	protected void assertNumberOfForms(int count) {
		assertEquals(count, forms.size());
	}

	protected void parseOneForm(String code) {
		parse(code);
		assertNumberOfForms(1);
	}

	protected Form form(int index) {
		return forms.get(index);
	}

	protected void assertEmpty(List<?> list) {
		assertEquals(0, list.size());
	}

	protected void assertVariable(String identifier, Object expression) {
		assertTrue(expression instanceof Variable);
		assertEquals(identifier, ((Variable) expression).getIdentifier());
	}

}